package controllayer;

import java.util.ArrayList;

import dblayer.DBConnection;
import dblayer.DBType;
import dblayer.IFDBType;
import modellayer.Type;

public class CtrType {

	private IFDBType dbObj;
	
	public CtrType(){
		dbObj = new DBType();
	}
	
	public ArrayList<Type> getAllTypes(){
		ArrayList<Type> list = new ArrayList<Type>();
		list = dbObj.getAllTypes();
		return list;
	}
	
	public Type searchByID(int id){
		return dbObj.searchByID(id);
	}
	
	public Type searchByType(String type){
		return dbObj.searchByType(type);
	}
	
	//
	
	public int updateType(int id, String type, String description){
		Type typeObj = new Type(id, type, description);
		
		return dbObj.updateType(typeObj);
	}
	
	public void createType(String type, String description){
		Type typeObj = new Type(type, description);
		
		try{
			DBConnection.startTransaction();
			dbObj.insertType(typeObj);
			DBConnection.commitTransaction();
		}
		catch(Exception e){
			DBConnection.rollbackTransaction();
		}
		
	}
	
	public int deleteType(int id){
		return dbObj.deleteType(id);
	}
}
